package com.aiyige.page.my.customer.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.my.customer.model.CustomerType;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class DialogCustomerScreen extends PopupWindow{

    View mView;

    Unbinder unbinder;

    @BindView(R.id.tv_all_customer)
    TextView tvAllCustomer;

    @BindView(R.id.tv_transaction_customer)
    TextView tvTransactionCustomer;

    @BindView(R.id.tv_intention_customer)
    TextView tvIntentionCustomer;

//    @BindView(R.id.tv_potential_customer)
//    TextView tvPotentialCustomer;
//
//    @BindView(R.id.tv_lose_customer)
//    TextView tvLoseCustomer;




    CallBack callBack;

    Context mContext;

    private String currentType = CustomerType.ALL_CUSTOMER;

    public DialogCustomerScreen(Context context, String currentType,CallBack callBack) {
        mContext = context;
        this.currentType = currentType;
        setCallBack(callBack);
        initData();
    }

//
    @OnClick({R.id.tv_all_customer,R.id.tv_transaction_customer, R.id.tv_intention_customer,R.id.id_space})
    public void onViewClick(View v) {
        switch (v.getId()) {
            case R.id.tv_all_customer:
                setCurrentType(CustomerType.ALL_CUSTOMER);
                break;
            case R.id.tv_transaction_customer:
                setCurrentType(CustomerType.TRANSACTION_CUSTOMER);
                break;
            case R.id.tv_intention_customer:
                setCurrentType(CustomerType.INTENTION_CUSTOMER);
                break;
//            case R.id.tv_potential_customer:
//                setCurrentType(CustomerType.POTENTIAL_CUSTOMER);
//                break;
//            case R.id.tv_lose_customer:
//                setCurrentType(CustomerType.LOSE_CUSTOMER);
//                break;
            case R.id.id_space:
                dismiss();
                break;

        }
    }


    private void initData() {
        this.mView = LayoutInflater.from(mContext).inflate(R.layout.dialog_customer_list_screen, null);
        setContentView(mView);
        ButterKnife.bind(this,mView);
        this.setHeight(RelativeLayout.LayoutParams.MATCH_PARENT);
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);

        // 设置弹出窗体可点击
        this.setFocusable(true);

        this.setOutsideTouchable(true);

//        tvAllCustomer.getPaint().setFakeBoldText(getCurrentType().equals(CustomerType.ALL_CUSTOMER));
//        tvAllCustomer.setSelected(getCurrentType().equals(CustomerType.ALL_CUSTOMER));
        tvTransactionCustomer.getPaint().setFakeBoldText(getCurrentType().equals(CustomerType.TRANSACTION_CUSTOMER));
        tvTransactionCustomer.setSelected(getCurrentType().equals(CustomerType.TRANSACTION_CUSTOMER));
        tvIntentionCustomer.getPaint().setFakeBoldText(getCurrentType().equals(CustomerType.INTENTION_CUSTOMER));
        tvIntentionCustomer.setSelected(getCurrentType().equals(CustomerType.INTENTION_CUSTOMER));
//        tvPotentialCustomer.getPaint().setFakeBoldText(getCurrentType().equals(CustomerType.POTENTIAL_CUSTOMER));
//        tvPotentialCustomer.setSelected(getCurrentType().equals(CustomerType.POTENTIAL_CUSTOMER));
//        tvLoseCustomer.getPaint().setFakeBoldText(getCurrentType().equals(CustomerType.LOSE_CUSTOMER));
//        tvLoseCustomer.setSelected(getCurrentType().equals(CustomerType.LOSE_CUSTOMER));
    }


    @Override
    public void dismiss() {
        super.dismiss();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }

    public String getCurrentType() {
        return currentType;
    }

    public void setCurrentType(String clientType) {
        currentType = clientType;
        initData();
        if (getCallBack() != null) {
            getCallBack().selectedCallback(currentType);
        }
        dismiss();
    }



    public interface CallBack {
        void selectedCallback(String type);
    }

    public CallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }
}
